package top.healthylife.gateway.platform.anxinsign.api.check;

import org.springframework.stereotype.Service;
import top.healthylife.basics.utils.exception.BusinessException;
import top.healthylife.gateway.core.config.BaseConfig;
import top.healthylife.gateway.core.service.CheckSecretService;
import top.healthylife.gateway.platform.anxinsign.api.config.SystemConfig;
import top.healthylife.gateway.platform.anxinsign.api.util.ExtEncryptAndDecrypt;

/**
 * @author : GaoZeXi
 * @date 2021/3/19 14:48
 */
@Service
public class CheckSecretServiceImpl implements CheckSecretService {
    @Override
    public void checkSecret(BaseConfig baseConfig) {
        SystemConfig brConfig = (SystemConfig) baseConfig;
        try {
            ExtEncryptAndDecrypt.check(brConfig.getPfxStream(), brConfig.getKeystore(), brConfig.getCerStream());
        } catch (Exception e) {
            throw new BusinessException("秘钥文件初始化失败:{}",e.getMessage());
        }
    }
}
